<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const maxNumOfSubarrays = (nums, k) => {
      let sum = 0, count = 1;
      for (const num of nums) {
        sum += num;
        if (sum > k) {
          sum = num;
          count++;
        }
      }
      return count;
    };
    console.log(maxNumOfSubarrays([2, -1, 2], 3));

  </script>
</body>

</html>